package com.maoxx.stuchoosemssbv_service.controller;

import com.maoxx.stuchoosemssbv_service.entity.CourseTeacherInfo;
import com.maoxx.stuchoosemssbv_service.entity.SCTInfo;
import com.maoxx.stuchoosemssbv_service.entity.StudentCourseTeacher;
import com.maoxx.stuchoosemssbv_service.service.SCTService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @className: SCTcontroller
 * @author: Maoxx
 * @date: 2024/11/4 22:58
 * @Version: 1.0
 * @description:
 */


@RestController
@RequestMapping("/SCT")
@CrossOrigin(origins = "*")
public class SCTController {

    @Autowired
    private SCTService sctService;

    @PutMapping("/save")
    public String save(@RequestBody StudentCourseTeacher studentCourseTeacher) {
        if (sctService.isSCTExist(studentCourseTeacher)) {
            return "禁止重复选课";
        }
        System.out.println("正在保存 sct 记录：" + studentCourseTeacher);
        return sctService.save(studentCourseTeacher) ? "选课成功" : "选课失败，联系管理员";
    }

    @GetMapping("/getSCTInfo")
    public List<SCTInfo> getSCTInfo() {
        return sctService.getSCTInfo();
    }

    @GetMapping("/findById/{sid}/{cid}/{tid}/{term}")
    public SCTInfo findById(@PathVariable Integer sid,
                            @PathVariable Integer cid,
                            @PathVariable Integer tid,
                            @PathVariable String term) {
        return sctService.findByIdWithTerm(sid, cid, tid, term);
    }


    @PutMapping("/updateById/{sid}/{cid}/{tid}/{term}/{grade}")
    public boolean updateById(@PathVariable Integer sid,
                              @PathVariable Integer cid,
                              @PathVariable Integer tid,
                              @PathVariable String term,
                              @PathVariable Integer grade) {
        return sctService.updateById(sid, cid, tid, term, grade);
    }

    @GetMapping("/deleteById/{sid}/{cid}/{tid}/{term}")
    public boolean deleteById(@PathVariable Integer sid,
                              @PathVariable Integer cid,
                              @PathVariable Integer tid,
                              @PathVariable String term) {
        return sctService.deleteById(sid, cid, tid, term);
    }

    @GetMapping("/findBySid/{sid}/{term}")
    public List<CourseTeacherInfo> findBySid(@PathVariable("sid") Integer sid, @PathVariable("term") String term) {
        return sctService.findBySid(sid, term);
    }

    @GetMapping("/findAllTerm")
    public List<String> findAllTerm() {
        return sctService.findAllTerm();
    }
}
